package com.yanqu.road.server.cmd.activity.dafuweng;

import com.yanqu.road.server.cmd.CrossUnionCommand;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.pb.monopoly.MonopolyProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.cross.battle.DaFuWengActivity;
import com.yanqu.road.server.manager.cross.battle.DaFuWengMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.server.protocol.GameErrorCode;

@Cmd(code = Protocol.C_CROSS_DA_FU_WENG_GET_UNION_NEWS, desc = "大富翁跨服获取商会情报")
public class CrossGetUnionNewsCmd extends CrossUnionCommand {

    private int activityId;
    private long serverId;
    private long userId;
    private String unionUid = "";

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        MonopolyProto.CrossGetUnionNewsReqMsg reqMsg = MonopolyProto.CrossGetUnionNewsReqMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        serverId = reqMsg.getServerId();
        unionUid = reqMsg.getUnionUid();
        userId = reqMsg.getUserId();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        DaFuWengActivity daFuWengActivity = DaFuWengMgr.getDaFuWengActivity(activityId, groupId);
        if (daFuWengActivity == null) {
            MonopolyProto.GetUnionNewsRespMsg.Builder builder = MonopolyProto.GetUnionNewsRespMsg.newBuilder();
            builder.setRet(GameErrorCode.E_ACTIVITY_DFW_NO_IN_TIME);
            YanQuMessage yanQuMessage = YanQuMessageUtils.buildMessage(ClientProtocol.U_DA_FU_WENG_GET_BOSS_DATA, builder);
            MessageHelper.sendPacket(serverId, userId, yanQuMessage);
            return;
        }

        daFuWengActivity.getUnionNews(unionUid, serverId, userId);
    }

    @Override
    public void sendData() {

    }
}